exports.__esModule = true;

var _TcpSocket = require('./TcpSocket');

var _TcpSocket2 = _interopRequireDefault(_TcpSocket);

var _Coordtransform = require('../../utils/Coordtransform');

var _Coordtransform2 = _interopRequireDefault(_Coordtransform);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

const Toc = new _TcpSocket2.default(think.config('videoConfig'));

// const nameSpace = think.config('nameSpace');
class CatalogVideo extends think.Service {
  constructor() {
    var _this;

    _this = super();
    Toc.on('catalogs', (() => {
      var _ref = _asyncToGenerator(function* (data) {
        const list = data.list;
        for (const value of list) {
          const lat = value.Lat;
          const lng = value.Lng;
          const type = value.type;
          if (Number(type) !== 2 && lat !== 0) {
            // 离线将wgs84地球坐标做换成百度坐标
            const points = _Coordtransform2.default.wgs84tobd09(lng, lat);
            value.Lng = points[0];
            value.Lat = points[1];
          }
          _this.db['basic_catalog_video'].upsert(value);
        }
      });

      return function (_x) {
        return _ref.apply(this, arguments);
      };
    })());
    Toc.on('error', data => {
      think.logger.error(data);
    });
  }

  ptzControl(deviceId, cmdType, speed) {
    Toc.ptz(deviceId, cmdType, speed);
  }
}

exports.default = CatalogVideo;